// Part 1
// You can call the provided async function fetchRole()
// to return the user role.
Future<String> fetchRole() {
  return Future.delayed(const Duration(seconds: 2), () => 'Large Latte');
}

Future<int> fetchLoginAmount() {
  return Future.delayed(const Duration(seconds: 2), () => 10);
}

Future<String> reportUserRole() async {
  var role = await fetchRole();
  return 'User role: $role';
}

// Part 2
// Implement reportLogins here
// You can call the provided async function fetchLoginAmount()
// to return the number of times that the user has logged in.
Future<String> reportLogins() async {
  var time1 = DateTime.now().millisecondsSinceEpoch;
  var numbers = await fetchLoginAmount();
  var time2 = DateTime.now().millisecondsSinceEpoch - time1;
  print('$time2');
  return 'Total number of logins: $numbers';
}

Future<void> main() async {
  await printOrderMessage();
}

Future<void> printOrderMessage() async {
  try {
    var order = await fetchUserOrder();
    print('Awaiting user order...'); // 不会执行
    print(order); // 不会执行
  } catch (err) {
    print('Caught error: $err');
  }
}

Future<String> fetchUserOrder() {
  // Imagine that this function is more complex.
  var str = Future.delayed(
      const Duration(seconds: 4), () => throw 'Cannot locate user order');
  return str;
}
